#include "gfxUnitDeathFX.h"
#include "soundsystem.h"
#include <QSound>

GFXUnitDeathFX::GFXUnitDeathFX(ClientEntity *entity, QGraphicsItem *parent)
   : GFXItem(entity, parent),
     mAlpha(255)
{
   mColor=entity->base.color;
   SoundSystem::instance()->playSound(SoundSystem::SFX_UNIT_DEATH);
}

GFXUnitDeathFX::~GFXUnitDeathFX()
{
}

QRectF GFXUnitDeathFX::boundingRect() const
{
   qreal penWidth = 1;
   return QRectF(-10 - penWidth / 2, -10 - penWidth / 2, 20 + penWidth, 20 + penWidth);
}


void GFXUnitDeathFX::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
   mAlpha-=5;
   if (mAlpha <= 128)
      mAlpha=128;

   QColor color = mColor;
   //color.setAlpha(mAlpha);
   QPen pen(color, 4);
   painter->setPen(pen);
   painter->drawEllipse(QPoint(0,0), mTicksAlive, mTicksAlive);

   //color.setAlpha(mAlpha/2);
   QPen pen2(color, 2);
   painter->setPen(pen2);
   painter->drawEllipse(QPoint(0,0), mTicksAlive*3, mTicksAlive*3);
}

void GFXUnitDeathFX::tick()
{

   mTicksAlive++;
   if (mTicksAlive>15)
      mActive = false;
   //qDebug() << "updateTowerBeam targeting=" << entity->target->id << "rot=" << rot;
   //update();
}
